package com.betterjr.modules.risk.loan.data;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.betterjr.modules.customer.entity.CustMechBankAccount;
import com.betterjr.modules.risk.loan.dao.FillBankAbstract;
import com.betterjr.modules.risk.loan.entity.LoanProjectBank;
import com.betterjr.modules.risk.loan.entity.LoanProjectRelation;

public class CustAggreationFillBank extends FillBankAbstract {

    private String flag = LoanProjectBankConstantCollections.LOANBANK_TYPE_CUSTAGGREATIONBANK;

    @Override
    public boolean fillBank(LoanProjectRelation anLoan, LoanProjectBank anBank) {

        if (anLoan != null && anBank != null && flag.equals(anBank.getType())) {
            anLoan.getCustAggregationBank().add(anBank);
            if (StringUtils.isNoneBlank(anLoan.getCustAggregationBankIds())) {

                anLoan.setCustAggregationBankIds(anLoan.getCustAggregationBankIds() + anBank.getBankId() + ",");
            } else {
                anLoan.setCustAggregationBankIds(anBank.getBankId() + ",");
            }
            return true;
        }

        return false;
    }

    @Override
    public void fillBank(LoanProjectRelation anLoan, List<CustMechBankAccount> accountList) {

        // 可归集账户银行
        List<CustMechBankAccount> custAccountBanks = getBankAccount(accountList, anLoan.getCustAggregationBankIds());
        for (CustMechBankAccount custMechBankAccount : custAccountBanks) {

            anLoan.getCustAggregationBank()
                    .add(LoanProjectBank.createBank(LoanProjectBankConstantCollections.LOANBANK_TYPE_CUSTAGGREATIONBANK,
                            custMechBankAccount, anLoan.getId()));
        }

    }

}
